<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*  原地移除数组元素，用的是双指针法
      slow代表完成修改的数组末尾，fast对数组遍历，如果符合条件就放到slow下标对应的位置
      */

      var removeElement = function (nums, val) {
        let slow = 0
        for (let i = 0; i < nums.length; i++) {
          if (nums[i] != val) {
            nums[slow] = nums[i]
            slow++
          }
        }
        return slow
      }
    </script>
  </body>
</html>
